#include "client.h"


int get_file_md5(const char * fileName, char* md5){
    FILE * fp = fopen(fileName, "rb");
    if(fp){
        fseek(fp, 0, SEEK_END);
        int fileSize = ftell(fp);
        fseek(fp, 0, SEEK_SET);
        unsigned char *Data = (unsigned char*)calloc(1, fileSize);
        fread(Data, 1, fileSize, fp);
        unsigned char md[MD5_DIGEST_LENTH] = {0};
        MD5(Data, fileSize, md);
        for(int i = 0; i < MD5_DIGEST_LENTH; ++i) {
            sprintf(&md5[2 * i], "%02x", *(md + i));
        }
        fclose(fp);
        return 0;
    }
    return -1;
}
